<template>
  <div class="boxs" v-loading="loading">
    <div class="f1">
      <div class="f1_content">
        <h1>请选择核心企业</h1>
        <div
          style="box-sizing: border-box; display: flex; flex-flow: wrap; padding-left: 0.0781rem"
        >
          <div
            v-for="(item, index) in EntList"
            :key="index"
            @click="cut(item, index)"
            class="f1_content_list"
            v-bind:class="{ row: row == index }"
          >
            <h2>{{ item.orgName }}</h2>
            <h3>{{ item.licenseno }}</h3>
          </div>
        </div>
      </div>
    </div>
    <div class="f2">
      <!-- 上一步/保存/提交 按钮 -->
      <div class="submit">
        <button :disabled="isLock" class="btn btn3" @click="addKJApplys()">去申请</button>
      </div>
    </div>
  </div>
</template>

<script>
import { myPostFetch, loginStatus } from '@/utils'
export default {
  data() {
    return {
      row: 0,
      isLock: false,
      disabled: false,
      loading: false,
      entId: '', //选择核心企业，保存企业id
      procedureId: '', // 从路由地址中获取产品ID,保存到状态变量中
      productcode: '', //产品码值
      productname: '', //产品名称
      ProductList: null,
      EntList: null
    }
  },

  // 生命周期方法
  mounted() {
    // 从路由地址中获取产品ID, 保存到状态变量中;
    this.procedureId = localStorage.getItem('id')
    this.productcode = localStorage.getItem('productcode')
    this.productname = localStorage.getItem('productname')
    this.getEntList()
  },
  methods: {
    // 切换选择核心企业
    cut(item, index) {
      this.entId = item.id
      this.row = index
    },
    // 获取核心企业列表
    async getEntList() {
      if (!sessionStorage.getItem('token')) return
      let datas = await loginStatus(sessionStorage.getItem('customerid'), 'SCF012003')
      if (datas.code == 10000) {
        this.$Message.error(datas.msg)
        this.$router.push('/login')
        sessionStorage.clear()
        localStorage.clear()
        return
      }
      this.loading = true
      let url = '/api/pros/productsubs0'
      let params = {
        productid: this.procedureId
      }
      let data = await myPostFetch(url, params)
      if (data.data == 'null' || data.data.length == 0) {
        this.loading = false
        return
      }
      if (data.code == 201) return (this.loading = false)
      if (data.data != null || data.data != []) {
        this.entId = data.data[0].id
        this.EntList = data.data
        this.loading = false
        return
      }
      this.loading = false
    },
    // 产品申请第1步
    async addKJApplys() {
      this.isLock = true
      setTimeout(() => {
        this.isLock = false
      }, 3000)
      localStorage.setItem('coopid', this.entId)
      if (this.productcode == 'SCF012001') {
        this.$router.push('/cyedApplication2')
      } else if (this.productcode == 'SCF012002') {
        this.$router.push('/gcqxdApplication')
      } else if (this.productcode == 'SCF012003') {
        this.$router.push('/fkcnhApply')
      } else if (this.productcode == 'SCF021001' || this.productcode == 'SCF027001') {
        this.$router.push('/SPBTApply')
      } else {
        this.$router.push('/ghdApplication')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.boxs {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
  background-color: #fff;
  .f1 {
    width: 100%;
    // height: 1.0417rem;
    margin-bottom: 0.1563rem;
    .f1_content {
      box-sizing: border-box;
      padding: 0 0.1823rem;
      width: 6.5104rem;
      // height: 1.0417rem;
      margin: 0 auto;
    }
    h1 {
      font-size: 0.1042rem;
      font-weight: 600;
      color: #424242;
      margin-bottom: 0.1042rem;
    }
    .f1_content_list {
      box-sizing: border-box;
      padding: 0 15px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      width: 1.9271rem;
      height: 0.5781rem;
      background: #fff;
      box-shadow: 0px 0.0417rem 0.1042rem 0px rgba(27, 63, 165, 0.5);
      border-radius: 0.0417rem;
      margin-right: 0.1042rem;
      margin-bottom: 0.1042rem;
      h2 {
        font-size: 0.0938rem;
        color: #3f6ef2;
        margin-bottom: 0.0781rem;
      }
      h3 {
        font-size: 0.0729rem;
        color: #b3bedb;
      }
      &.row {
        box-sizing: border-box;
        background-color: #3f6ef2;

        h2 {
          color: #fff;
        }
        h3 {
          color: #fff;
        }
      }
    }
    .f1_content_list:nth-of-type(3n) {
      margin-right: 0px;
    }
  }
  // 按钮组
  .submit {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 0.2604rem;
    margin: 0.026rem 0 0.026rem 0;

    .btn {
      cursor: pointer;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 0.9375rem;
      height: 0.1979rem;
      background: linear-gradient(-90deg, #5d98f8, #4b5af8);
      box-shadow: 0px 0.0313rem 0.1042rem 0px rgba(0, 40, 193, 0.5);
      border-radius: 0.0208rem;
      font-size: 0.0938rem;
      font-family: Source Han Sans SC;
      font-weight: 400;
      color: #ffffff;
      margin-right: 0.1563rem;
    }
    .btn1 {
      background-color: #bfbfbf;
    }
    // 提交按钮
    .btn3 {
      background-color: #738bd0;
    }
  }
}
</style>
